import { createRouter, createWebHistory, RouterOptions } from 'vue-router';
import { staticsRouter } from './statics.ts';

const router = createRouter(<RouterOptions>{
  strict: true,
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: LOGIN_URL,
      name: LOGIN_NAME,
      component: () => import('@/views/basic/login/index.vue')
    },
    {
      path: HOMEPAGE_URL,
      name: HOMEPAGE_NAME,
      redirect: HOME_URL, // 自动重定向到首页路由
      component: () => import('@/views/basic/homepage/index.vue'),
      children: [
        {
          path: HOME_URL,
          name: HOME_NAME,
          component: () => import('@/views/pages/home/index.vue')
        },
        {
          path: HOMEPAGE_URL + ':catchAll(.*)',
          name: HOMEPAGE_NAME + ':unknown',
          component: () => import('@/views/basic/error/unknown/index.vue')
        },
        ...staticsRouter
      ]
    },
    {
      path: '/:catchAll(.*)',
      name: 'unknown',
      component: () => import('@/views/basic/error/unknown/index.vue')
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: HOMEPAGE_URL
    }
  ]
});

router.beforeEach(async (_to, _from, next) => {
  next();
});

router.afterEach((_to, _from) => {
});

export default router;